import os
import random
import time
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

# 加载浏览器驱动
service = Service(executable_path=os.path.join(os.path.dirname(__file__), "chromedriver.exe"))
browser = Chrome(service=service)

# 访问百度
target_url = 'https://www.baidu.com'

browser.get(target_url)

time.sleep(random.randint(1, 8))

# 获取输入框并输入内容
search_input = browser.find_element(By.ID, 'kw')
search_input.send_keys('python')

time.sleep(random.randint(1, 8))

# 获取搜索按钮并点击
search_button = browser.find_element(By.ID, 'su')
search_button.click()
time.sleep(random.randint(1, 8))
